package utils

import "time"

const (
	Minute = int64(60)
	Hour   = 60 * Minute
	Day    = 24 * Hour
	Week   = 7 * Day
	Month  = 30 * Day
	Year   = 12 * Month
)

// GetToday0 获取今天0点的时间戳
func GetToday0() time.Time {
	now := time.Now()
	return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
}

// GetToday24 获取今天24的时间戳
func GetToday24() time.Time {
	now := time.Now()
	return time.Date(now.Year(), now.Month(), now.Day(), 24, 0, 0, 0, now.Location())
}

// GetDayList 获取时间范围内连续的时间戳字符串，时间戳为天 yyyy-MM-dd
// eg ：[2025-01-02 2025-01-03 2025-01-04 2025-01-05 2025-01-06 2025-01-07 2025-01-08 2025-01-09]
func GetDayList(startTime, endTime int64) (li []string) {
	now := time.Unix(startTime, 0)
	for {
		li = append(li, now.Format("2006-01-02"))
		now = now.Add(time.Hour * 24)
		if now.Unix() > endTime {
			break
		}
	}
	return li
}

// GetDayListByNow 获取一个时间戳字符串，时间为当前时间往前推N天
// eg: [2025-01-02 2025-01-03 2025-01-04 2025-01-05 2025-01-06 2025-01-07 2025-01-08 2025-01-09]
func GetDayListByNow(dayNum int64) (li []string) {
	endTime := time.Now().Unix()
	startTime := endTime - Day*dayNum
	return GetDayList(startTime, endTime)
}
